SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE dbo.[DnnProduct_CDS_DistributorUserGet]
	@ID int
AS
BEGIN
	DECLARE @DistID_PID int
	SELECT @DistID_PID = PropertyDefinitionID FROM [DnnProduct_ProfilePropertyDefinition] WHERE PropertyName = 'DistID'
	
	DECLARE @DistName_PID int
	SELECT @DistName_PID = PropertyDefinitionID FROM [DnnProduct_ProfilePropertyDefinition] WHERE PropertyName = 'DistributorName'

	/* Build the SQL string once.*/
	SELECT U.[UserID] AS [ID], UP1.[PropertyValue] AS DistID, UP2.[PropertyValue] AS DistName, U.[Username], U.[DisplayName] FROM [DnnProduct_Users] U
	JOIN [DnnProduct_UserProfile] UP1 ON UP1.UserID = U.UserID AND UP1.PropertyDefinitionID = @DistID_PID
	JOIN [DnnProduct_UserProfile] UP2 ON UP2.UserID = U.UserID AND UP2.PropertyDefinitionID = @DistName_PID
	WHERE U.[UserID] = @ID
END
GO
